package gui;

import gameBasicElements.PlayerColor;
import gameEngine.GameInfo;

import javax.swing.*;

/**
 * @author Wojciech Łopata
 *
 */

public class GameInfoPanel extends JPanel
{
	private static final long serialVersionUID = -5929681622478007958L;
	
	private final CurrentPlayerInfoPanel currentPlayerInfoPanel;
	private final PlayerInfoPanel blackPlayerInfoPanel;
	private final PlayerInfoPanel whitePlayerInfoPanel;
	private final GameMessagePanel gameMessagePanel;
	private GameInfo info;
	
	public GameInfoPanel()
	{
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		currentPlayerInfoPanel = new CurrentPlayerInfoPanel();
		blackPlayerInfoPanel = new PlayerInfoPanel(PlayerColor.BLACK);
		whitePlayerInfoPanel = new PlayerInfoPanel(PlayerColor.WHITE);
		gameMessagePanel = new GameMessagePanel();
		
		add(currentPlayerInfoPanel);
		add(blackPlayerInfoPanel);
		add(whitePlayerInfoPanel);
		add(gameMessagePanel);
	}
	
	public void startDrawing(GameInfo info)
	{
		this.info = info;
		blackPlayerInfoPanel.startDrawing(info);
		whitePlayerInfoPanel.startDrawing(info);
	}
	
	public void stopDrawing()
	{
		blackPlayerInfoPanel.stopDrawing();
		whitePlayerInfoPanel.stopDrawing();
	}
	
	public void updatePanel()
	{
		currentPlayerInfoPanel.updatePlayerColor(info.getCurrentPlayer());
		gameMessagePanel.setMessage(info.lastMoveError());
	}
}
